#ifndef CONDITION_H
#define CONDITION_H

#include <pthread.h>
#include <time.h>
class condition
{
private:
    pthread_cond_t m_cond;
public:
    condition(/* args */)
    {
        if(pthread_cond_init(&m_cond,NULL)!=0)
            throw std::exception();
    }

    ~condition()
    {
        pthread_cond_destroy(&m_cond);
    }

    bool wait(pthread_mutex_t * m_mutex)
    {
        return pthread_cond_wait(&m_cond,m_mutex)==0;
    }

    bool waitintime(pthread_mutex_t * m_mutex,struct timespec t)
    {
        return pthread_cond_timedwait(&m_cond,m_mutex,&t) == 0;
    }

    bool signal()
    {
        return pthread_cond_signal(&m_cond) == 0;
    }

    bool broadsignal()
    {
        return pthread_cond_broadcast(&m_cond) == 0;
    }
};

#endif
